home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / appl / askhost / askhost.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  1.8 KB  |  78 lines

  1. /*
  2.  * $Id: askhost.c,v 1.2 1994/02/08 11:48:00 too Exp $
  3.  *
  4.  * Author: Tomi Ollila <too@cs.hut.fi>
  5.  *
  6.  * Copyright (c) 1993, 1994  AmiTCP/IP Group, <amitcp-group@hut.fi>
  7.  *                           Helsinki University of Technology, Finland.
  8.  *                           All rights reserved.
  9.  *
  10.  * Created: Fri May 28 15:22:12 1993 too
  11.  * Last modified: Tue Feb  8 13:35:27 1994 too
  12.  *
  13.  * HISTORY
  14.  * $Log: askhost.c,v $
  15.  * Revision 1.2  1994/02/08  11:48:00  too
  16.  * Now copies h_addr_list[i] to aligned struct in_addr buffer
  17.  *
  18.  * Revision 1.1  1994/02/02  17:48:57  too
  19.  * Initial revision
  20.  */
  21.  
  22. #ifndef AMIGA    /* no stdio for AMIGA version for smaller executable size. */
  23. #include <stdio.h>
  24. #else
  25. #include "amiga.h"
  26. #endif
  27.  
  28. #include <sys/types.h>
  29. #include <sys/socket.h>
  30. #include <netdb.h>
  31.  
  32. int main(int argc, char *argv[])
  33. {
  34.   struct hostent * host;
  35.   int i;
  36.  
  37.   if (argc < 2) {
  38.     printf("Usage: askhost (<name>|<addr>)\n");
  39.     return 1;
  40.   }
  41.   
  42.   if (argv[1][0] >= '0' && argv[1][0] <= '9') {
  43.     unsigned long ia;
  44.     if ((ia = inet_addr(argv[1])) == -1) {
  45.       printf("inet_addr: malformed request\n");
  46.       return 1;
  47.     }
  48.     if ((host = gethostbyaddr((char *)&ia, 4, AF_INET)) == NULL) {
  49.       herror("gethostbyaddr");
  50.       return 1;
  51.     }
  52.   }
  53.   else {
  54.     if ((host = gethostbyname(argv[1])) == NULL) {
  55.       herror("gethostbyname");
  56.       return 1;
  57.     }
  58.   }    
  59.     
  60.   printf("\nhost: %s   addrtype: %ld   length: %ld\n"
  61.      "aliases:\n", host->h_name, host->h_addrtype, host->h_length);
  62.  
  63.   for (i = 0; host->h_aliases[i]; i++)
  64.     printf("    %s\n", host->h_aliases[i]);
  65.  
  66.   printf("address list:\n");
  67.  
  68.   for (i = 0; host->h_addr_list[i]; i++) {
  69.     struct in_addr addr;
  70.  
  71.     bcopy(host->h_addr_list[i], (char *)&addr, sizeof addr); 
  72.     printf("    %s\n", inet_ntoa(addr));
  73.   }
  74.   printf("\n");
  75.  
  76.   return 0;
  77. }    
  78.